home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / System / Chassis 6.0 ƒ / myActionProc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-22  |  5.9 KB  |  150 lines  |  [TEXT/KAHL]

  1. /************************************************************************************/
  2. /*    myActionProc                                                                    */
  3. /*    Called when there is a mouse click on a control part.                            */
  4. /*                                                                                    */
  5. /*    Note:    although the physical location of destRect doesn't change, scrolling    */
  6. /*            and autoscroll change the value of destRect.top                            */
  7. /*                                                                                    */
  8. /*    Thanks to the following for contributions to fix an error which was preventing    */
  9. /*    this routine from running in 32-bit mode on Mac-IIci and above:                    */
  10. /*                                                                                    */
  11. /*    Jim Ulrey and                             -    Identified the error, and verified    */
  12. /*    Paul Bennell (paul@chiron.com.au)            that it only occured in 32-bit        */
  13. /*                                                mode.  Isolated the problem to the    */
  14. /*                                                call to TrackAction when the        */
  15. /*                                                mouseDown event was not in the        */
  16. /*                                                thumbwheel part of the control.        */
  17. /*                                                                                    */
  18. /*    Marcelino Bernardo (mBernar@erenj.com)    -    Found the problem in the incorrect    */
  19. /*                                                definition of myActionProc as        */
  20. /*                                                'pascal Boolean' instead of            */
  21. /*                                                'pascal void'.                        */
  22. /************************************************************************************/
  23.  
  24. #include "MyHeaders.h"
  25.  
  26. pascal void myActionProc(ControlHandle theControl, short partCode)        /* 5.1.2    */
  27. {
  28.     WindowPtr        theWindow;
  29.     TEHandle        theTE;
  30.     short                vView;                        /* height of viewRect rounded        */
  31.     short                vViewP;                        /* height of viewRect not rounded    */
  32.     short                vLine;                        /* height of one line of text        */
  33.     short                vTotal;                        /* total height of text                */
  34.     short                vAmount;                    /* total amount that can be scroled    */
  35.     short                vScrlAmt;                    /* scroll amount                    */
  36.     div_t            r;                            /* work area for division            */
  37.     short                tAdjust;                    /* amount to adjust thumb scrolling    */
  38.     short                teHSub;                        /* subscript of active TE item        */
  39.  
  40.     teHSub = windTbl[windSub].windTEHSub;                    /* set the subscript    */
  41.     
  42.     theWindow = ((WindowPtr) (**theControl).contrlOwner);        /* ptr to window    */
  43.     WhichWindow (theWindow, &windSub);                            /* subscr to table    */
  44.     theTE = windTbl[windSub].windTEH[teHSub];                    /* handle to TE rec    */
  45.  
  46.     vLine = (**theTE).lineHeight;                                /* height of 1 line    */
  47.     vViewP = (**theTE).viewRect.bottom -(**theTE).viewRect.top;    /* height of 1 page    */
  48.     vView = (vViewP / vLine) * vLine;                            /* rounded to lines    */
  49.     vTotal = (**theTE).nLines * (**theTE).lineHeight;            /* height whole txt    */
  50.     if ((**theTE).teLength > 0                                     /* if ends in c/r    */
  51.         && (*((**theTE).hText))[(**theTE).teLength-1]=='\r')    /*    adjust for it    */
  52.             vTotal += (**theTE).lineHeight;
  53.  
  54.     switch (partCode)
  55.         {
  56.         case (inUpButton):
  57.             vScrlAmt = ((**theTE).viewRect.top > (**theTE).destRect.top + vLine)
  58.                     ? vLine
  59.                     : (**theTE).viewRect.top - (**theTE).destRect.top;
  60.             if (vScrlAmt < 0)                    /* if calculation has wrong sign    */
  61.                 vScrlAmt = 0;                    /* don't scroll                        */
  62.         break;
  63.                 
  64.         case (inPageUp):
  65.             vScrlAmt = ((**theTE).viewRect.top > (**theTE).destRect.top + vView)
  66.                     ? vView
  67.                     : (**theTE).viewRect.top - (**theTE).destRect.top;
  68.             if (vScrlAmt < 0)                    /* if calculation has wrong sign    */
  69.                 vScrlAmt = 0;                    /* don't scroll                        */
  70.         break;
  71.         
  72.         case (inPageDown):
  73.             vScrlAmt = ((**theTE).viewRect.bottom 
  74.                         < (**theTE).destRect.top + vTotal - vView) 
  75.                     ? -vView 
  76.                     : -((**theTE).destRect.top + vTotal - (**theTE).viewRect.bottom);
  77.             if (vScrlAmt > 0)                    /* if calculation has wrong sign    */
  78.                 vScrlAmt = 0;                    /* don't scroll                        */
  79.         break;
  80.                 
  81.         case (inDownButton):
  82.             vScrlAmt = ((**theTE).viewRect.bottom 
  83.                         < (**theTE).destRect.top + vTotal - vLine) 
  84.                     ? -vLine 
  85.                     : -((**theTE).destRect.top + vTotal - (**theTE).viewRect.bottom);
  86.             if (vScrlAmt > 0)                    /* if calculation has wrong sign    */
  87.                 vScrlAmt = 0;                    /* don't scroll                        */
  88.         break;
  89.         
  90.         case (inThumb):
  91.                                                 /* current value of control            */
  92.             j = GetCtlValue (theControl);        /*   after moving thumb                */
  93.             
  94.                                                 /* difference in control value        */
  95.             vScrlAmt = k;                        /*   due to moving thumb            */
  96.             
  97.                                                 /* how much more or less than whole    */
  98.             r = div (vScrlAmt, vLine);            /*   number of lines in the scroll?    */
  99.             
  100.                                                 /* compute adjustment to the scroll    */
  101.                                                 /*   amount and the control value    */
  102.                                                 /*   to result in only scrolling a    */
  103.                                                 /*   whole number of lines            */
  104.                                                 
  105.             if (abs(r.rem) < vLine/2)                /* if we should round down        */
  106.                 tAdjust = -r.rem;                    /*   use this                    */
  107.             else                                    /* else                            */
  108.                 {                                    /* if we should round up        */
  109.                 if (r.rem > 0)                        /*   if we are scrolling up        */
  110.                     tAdjust = -r.rem + vLine;        /*        use this                */
  111.                 else                                /*   else if scrolling down        */
  112.                     tAdjust = -r.rem - vLine;        /*      use this                */
  113.                 }
  114.                     
  115.             vScrlAmt += tAdjust;                /* adjust scroll amt (scroll later)    */
  116.             
  117.             if (tAdjust != 0)                    /* adjust control amount and redraw    */
  118.                 SetCtlValue (theControl, (j - tAdjust));
  119.         break;
  120.         
  121.         case (0):
  122.             vScrlAmt = 0;
  123.                                                 /* If the total vertical length of    */
  124.                                                 /* the text now is less than the    */
  125.                                                 /* height of the viewRect, prepare    */
  126.                                                 /* to scroll to the top of viewRect    */
  127.             if ((vViewP >= vTotal)
  128.                     && ((**theTE).viewRect.top != (**theTE).destRect.top))
  129.                 vScrlAmt = (**theTE).viewRect.top - (**theTE).destRect.top;    
  130.         break;
  131.         
  132.         default:
  133.             return;                                            /* 5.1.2                */
  134.         }
  135.         
  136.     TEScroll (0, vScrlAmt, theTE);                            /* do the scroll        */            
  137.  
  138.     vAmount = (vTotal > vViewP) ? vTotal-vViewP : 0;        /* ..max scrollable amt    */
  139.     if (vAmount == 0)                                        /* ..if view > text        */
  140.         (**theTE).destRect.top = (**theTE).viewRect.top;    /* ..  fit all in view    */
  141.     
  142.     if (GetCtlMax (theControl) != vAmount)                    /* set max to..            */
  143.         SetCtlMax(theControl, vAmount);                        /* .. max scrollable    */
  144.         
  145.     if (partCode != inThumb)                                /* reset and redraw        */
  146.         SetCtlValue (theControl, ((**theTE).viewRect.top) - (**theTE).destRect.top);
  147.     
  148.     return;                                                 /* 5.1.2                */
  149. }
  150.